// -*- c++ -*-
/**************************************************************/
/*  This file is licensed from, and is a trade secret of:     */
/*                                                            */
/*    Mercury Computer Systems, Incorporated                  */
/*    199 Riverneck Road                                      */
/*    Chelmsford, Massachusetts 01824-2820                    */
/*    United States of America                                */
/*    Telephone + 1 978 256-1300                              */
/*                                                            */
/*  Refer to your Software License Agreement for provisions   */
/*  on use, duplication, or disclosure.                       */
/*  US. Government users and prime contractors are also       */
/*  governed by the following Data Rights Notice:             */
/*  Use, duplication or disclosure by the US. Government is   */
/*  subject to the provisions set forth in FAR 52.227-14 for  */
/*  restricted rights or other agency data rights provisions  */
/*  on commercial software and documentation, as applicable.  */
/*                                                            */
/*  This file: (a) was developed at private expense, and no   */
/*  part was developed with government funds, (b) is a        */
/*  trade secret of Mercury Computer Systems, Inc. for the    */
/*  purposes of the Freedom of Information Act, (c) is        */
/*  "commercial computer software" subject to limited         */
/*  utilization as provided in the above noted Software       */
/*  License Agreement and (d) is in all respects data         */
/*  belonging exclusively to Mercury Computer Systems, Inc..  */
/*                                                            */
/**************************************************************/

/******************************************************************/
/* Copyright (c) 1999-2003, Mercury Computer Systems, Inc.,       */
/* Chelmsford MA.,and all third party embedded software sources.  */
/* All rights reserved under the Copyright laws of US. and        */
/* international treaties.                                        */
/*                                                                */
/* Patent Pending                                                 */
/******************************************************************/

//$COPYRIGHT_END

#ifndef BITPACKETIZER_H__
#define BITPACKETIZER_H__


#include <iostream>
#include <string>
#include "CF__Resource_impl.h"
#include "AudioPort_impl.h"
#include "SceOsSemaphore.h"
#include "SceOsThreadManager.h"
#include "mc_error.h"

#ifdef _WIN32
#ifdef BITPACKETIZER_EXPORTS
#define BITPACKETIZER_EXPORT __declspec(dllexport)
#else
#define BITPACKETIZER_EXPORT __declspec(dllimport)
#endif
#else
#define BITPACKETIZER_EXPORT 
#endif


class BITPACKETIZER_EXPORT Packetizer7to5 : public CF__Resource_impl {
public: 
  static status
  Create (Packetizer7to5 *& ModulatorHandle,
	  const char * identifier);

  // From CF::Resource
  void start ()
    throw (CORBA::SystemException, CF::Resource::StartError);
  void stop ()
    throw (CORBA::SystemException, CF::Resource::StopError);

  // From CF::PortSupplier
  CORBA::Object_ptr getPort (const CORBA::Char * name)
    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);

private:
  Packetizer7to5 (const char * identifier);
  ~Packetizer7to5 ();

  status Init ();

  // Separate thread master function.
  static void RunWorker (void * param);
  // Inner loop function that deals with external commands.
  status RunLoop ();
  // Inner loop method that performs component business logic.
  status Run (); 

  // Port definitions
  BitPacketizerOutPort_impl * m_bitpacketizerout;
  RsBlockInPort_impl * m_bitpacketizerin;

  char * m_input;
  char * m_output;
  long m_loopsCompleted;

  bool m_bStop;
  bool m_threadrunning;
  SCE::OS::ThreadManager m_thread;
};


class BITPACKETIZER_EXPORT Packetizer5to7 : public CF__Resource_impl {
public:
  static status
  Create (Packetizer5to7 *& DemodHandle,
	  const char * identifier);

  // From CF::Resource
  void start ()
    throw (CORBA::SystemException, CF::Resource::StartError);
  void stop ()
    throw (CORBA::SystemException, CF::Resource::StopError);

  // From CF::PortSupplier
  CORBA::Object_ptr getPort (const CORBA::Char * name)
    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort);

private:
  Packetizer5to7 (const char * identifier);
  ~Packetizer5to7 ();

  status Init ();

  // Separate thread master function.
  static void RunWorker (void * param);
  // Inner loop function that deals with external commands.
  status RunLoop();
  // Inner loop method that performs component business logic.
  status Run (); 

  // Port definitions
  BitPacketizerInPort_impl * m_bitpacketizerin;
  RsBlockOutPort_impl * m_bitpacketizerout;

  char * m_input;
  char * m_output;
  unsigned int m_output_count;

  bool m_bStop;
  bool m_threadrunning;
  SCE::OS::ThreadManager m_thread;
};

#endif /* BITPACKETIZER_H__ */
